<?php

/*
 * This class is used for as Model for Product table 
 */

class Model_Propertymaintagtype extends Model_Base {

    protected $_name = 'property_tag_type_name';
    protected $_primaryKey = 'prp_typename_id';

    
    
     public function fetchEntryByREFId($id) {
        $select = $this->select()
                ->from(array('prp' => 'property_tag_type_name'))
                ->setIntegrityCheck(false)
                ->join(array('ln' => 'languages'), "prp.prp_typename_lang_id = ln.lang_id")
                ->where('prp_typename_ref_id = ?', $id);
        // see reasoning in fetchEntries() as to why we return only an array
        $data = $this->fetchAll($select);
        if (!empty($data)) {
            return $data->toArray();
        } else {
            return array();
        }
    }
    
    public function fetchEntryById($id) {
        $select = $this->select()
                ->from(array('prp' => 'property_tag_type_name'))
                ->setIntegrityCheck(false)
                ->join(array('ln' => 'languages'), "prp.prp_typename_lang_id = ln.lang_id")
                ->where('prp_typename_id = ?', $id);
        // see reasoning in fetchEntries() as to why we return only an array
        $data = $this->fetchRow($select);
        if (!empty($data)) {
            return $data->toArray();
        } else {
            return array();
        }
    }
    
    
    
    /**
     *  This function is used to get Questions
     * @return null|Zend_Db_Table_Row_Abstract
     */
    
    public function  fetchcategoryArray($where){
        
        $result = $this->fetchallmaintag($where,"","0",'prp_typename_id','ASC');
        
        $finalArray[''] = 'Select Category';
        foreach ($result as $user) {
            $finalArray[$user['prp_typename_id']] = $user['prp_typename_name'];
        }
        return $finalArray;
    }
    
    
    public function fetchPropertymaintagtype($where = "", $limit = "", $offset = "0", $order = 'prp_typename_id', $sort = 'ASC') {
        $select = $this->select()
                ->from(array('prtyp' => 'property_tag_type_name'));
        if ($where != '') {
            $select->where($where);
        }
        if ($limit != "") {
            $select->limit($limit, $offset);
        }
        $select->order($order . " " . $sort);
        $data = parent::fetchAll($select);
        if (!empty($data)) {
            $finalArray = array();
            foreach($data->toArray() as $_property_type) {
                $finalArray[$_property_type['prp_typename_id']] = $_property_type['prp_tgtype_title'];
            }
            return $finalArray;
        } else {
            return array();
        }
    }
    
     public function fetchallmaintag($where = "", $limit = "", $offset = "0", $order = 'prp_typename_id', $sort = 'ASC', $group = 'prp_typename_ref_id') {
         $select = $this->select()
                ->from(array('prtyp' => 'property_tag_type_name'), array('*','lang_names' => new Zend_Db_Expr('GROUP_CONCAT(ln.lang_name)')) )
                ->setIntegrityCheck(false)
                ->join(array('ln' => 'languages'), "prtyp.prp_typename_lang_id = ln.lang_id")
                ->where('prtyp.prp_type_publish != 2')
                ->where('prtyp.prp_typename_name != ""');
        
        if ($where != '') {
            $select->where($where);
        }
        if ($group != "") {
            $select->group($group);
        }
         $select->order($order . " " . $sort);
        $result = $this->fetchAll($select);
        #echo $select;exit;
        if (!empty($result)) {
            return $result->toArray();
        } else {
            return array();
        }
    }
    
      /**
     *  This function is used to get total orders
     * @return int
     */
    
    public function getCategoryCount($where) {
        
        $select = $this->select()
                ->from(array('prp' => 'property_tag_type_name'), Array('cnt' => 'count(*)'))
                ->setIntegrityCheck(false)
                ->join(array('ln' => 'languages'), "prp.prp_typename_lang_id = ln.lang_id")
                ->where('prp.prp_type_publish != 2')
                ->where('prp.prp_typename_name != ""')
                ->group('prp_typename_ref_id');
        if ($where != '') {
            $select->where($where);
        }
       
        #echo $select;exit;
        $rows = parent::fetchRow($select);
       // echo $rows->cnt;exit;
        return($rows->cnt);
    }

   
}
